package com.kaoshi.myweb.webstruts.controller;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;

import com.opensymphony.xwork2.ActionSupport;

public class FileUploadAction extends ActionSupport {
	private String filename;
	
	private File myFile;
	private String myFileFileName;
	private String myFileContentType;
	
	
	public String getMyFileFileName() {
		return myFileFileName;
	}

	public void setMyFileFileName(String myFileFileName) {
		this.myFileFileName = myFileFileName;
	}

	public String getMyFileContentType() {
		return myFileContentType;
	}

	public void setMyFileContentType(String myFileContentType) {
		this.myFileContentType = myFileContentType;
	}

	public String getFilename() {
		return filename;
	}

	public void setFilename(String filename) {
		this.filename = filename;
	}

	public File getMyFile() {
		return myFile;
	}

	public void setMyFile(File myFile) {
		this.myFile = myFile;
	}

	@Override
	public String execute() throws Exception {
		
		OutputStream outputStream = null;
		InputStream inputStream = null;
		
		try {
			outputStream = new FileOutputStream("d:/" + filename);
			byte[] bs = new byte[1024];
			inputStream = new FileInputStream(myFile);
			
			int length = 0;
			while ((length = inputStream.read(bs)) > 0) {
				outputStream.write(bs,0, length);
			}
		} catch (Exception e) {
			// TODO: handle exception
		}
		finally
		{
			inputStream.close();
			outputStream.close();
		}
		return super.execute();
	}

}
